package com.hxkj.controller.article;

import com.hxkj.domain.po.Advertisement;
import com.hxkj.service.article.AdvertisementService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 广告管理,广告的增删改查
 * Created by chenfangzhou on 2018年9月7日
 */
@RestController
@RequestMapping("/advertisement")
public class AdvertisementController {

    @Autowired
    private AdvertisementService advertisementService;

    /**
     * 获取单条广告信息数据
     *
     * @param advertisement
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public ResultDataStruct<Advertisement> get(@ModelAttribute Advertisement advertisement) throws Exception {

        return advertisementService.get(advertisement);
    }

    /**
     * 新增广告信息
     *
     * @param advertisement
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultMessageStruct save(@ModelAttribute Advertisement advertisement) throws Exception {
        return advertisementService.save(advertisement);
    }


    /**
     * 修改广告信息
     *
     * @param advertisement
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultMessageStruct modify(@ModelAttribute Advertisement advertisement) throws Exception {
        return advertisementService.modify(advertisement);
    }

    /**
     * 删除广告信息(可删除多条)
     *
     * @param advertisement
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ResultMessageStruct remove(@ModelAttribute Advertisement advertisement) throws Exception {
        return advertisementService.remove(advertisement);
    }


    /**
     * 获取所有的广告列表,带分页
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getListWithPage", method = RequestMethod.POST)
    public ResultPageStruct<Advertisement> getListWithPage(@ModelAttribute Advertisement advertisement, @ModelAttribute PageTo pageTo) throws Exception {
        return advertisementService.getListWithPage(advertisement == null ? new Advertisement() : advertisement, pageTo);
    }


    /**
     * 获取所有的广告列表,不带分页
     *
     * @param advertisement
     * @throws Exception
     */
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public List<Advertisement> getList(@ModelAttribute Advertisement advertisement) throws Exception {
        return advertisementService.getList(advertisement);
    }

    /**
     * 修改广告排序
     * @param map
     * @throws Exception
     */
    @RequestMapping(value = "/modifysortnum", method = RequestMethod.POST)
    public void modifySortNum(@RequestParam HashMap<String, Object> map) throws Exception {
        advertisementService.modifySortNum(map);
    }
}
